package com.uchedao.seller.manager;

import android.app.Activity;

import java.util.Stack;

public class ActivityManager {

	private static Stack<Activity> activityStack;
	private static ActivityManager instance;
	
	private ActivityManager() {
		activityStack = new Stack<Activity>();
	}
	
	public static ActivityManager getInstance() {
		if(instance == null)
			instance = new ActivityManager();
		return instance;
	}
	
	public void popActivity(Activity activity) {
		if(activity != null) {
			activity.finish();
			activityStack.remove(activity);
			activity = null;
		}
	}
	
	public Activity currentActivity() {
		return activityStack.isEmpty()? null : activityStack.lastElement();
	}
	
	public void pushActivity(Activity activity) {
		activityStack.push(activity);
	}
	
	public void clearAllActivity(Class clz) {
		while(true) {
			Activity activity = currentActivity();
			if(activity == null)
				break;
			if(activity.getClass().equals(clz))
				break;
			popActivity(activity);
		}
	}
}
